<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="int1">
    <input type="text" id="int2">
    <button id="btn">登录</button>
</body>
<script>
    // 作业2：用户登录

    // ​	接口地址： https://liu.zzgoodqc.cn/login   POST

    // ​	登录数据字段： username,password

    // ​	用户名密码是作业1自己注册

    window.onload = function () {
        document.getElementById('btn').onclick = function () {
            var username = document.getElementById('int1').value,
                password = document.getElementById('int2').value

            var xhttp = new XMLHttpRequest()
            xhttp.open('POST', 'https://liu.zzgoodqc.cn/login', true)
            xhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded')

            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    var dataobj = JSON.parse(xhttp.responseText)
                }
            }

            var data = 'username=' + username + '&password=' + password

            xhttp.send(data)
        }



    }

</script>

</html>